package com.xmkj.winmoney.home;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.common.Entity.HomeEntity;
import com.common.cons.Constans;
import com.common.utils.EmptyUtils;
import com.common.utils.SPUtils;
import com.common.utils.TimeUtils;
import com.common.widget.CountDown.CountdownView;
import com.common.widget.recyclerview.refresh.adapter.CommonAdapter;
import com.common.widget.recyclerview.refresh.adapter.ViewHolder;
import com.xmkj.winmoney.R;
import com.xmkj.winmoney.count.LoginActivtiy;
import com.xmkj.winmoney.jifen.JinPaiDetailActivity;

import java.util.List;

/**
 * Create by leo
 * 创建日期：2018/5/4
 * 描述：
 */

public class HomeSonAdapter extends CommonAdapter<HomeEntity.ListsEntity> {
    int type;

    public HomeSonAdapter(Context context, List<HomeEntity.ListsEntity> data, int position) {
        super(context, data);
        this.type = position;
    }

    @Override
    protected void convert(ViewHolder holder, final HomeEntity.ListsEntity item, int position) {
        CountdownView countdownView = holder.getView(R.id.count_down);
        long time = TimeUtils.getStringToDate(item.remainingdatestr) - TimeUtils.getStringToDate(item.now_time);
        countdownView.start(time);
//        holder.setImageAvatar(R.id.iv_img, item.goodsthumb);
     /*   ImageView ivImg = holder.getView(R.id.iv_img);
        String imgPath = item.goodsthumb;
        if (!imgPath.equals(ivImg.getTag())) {//解决图片加载不闪烁的问题,可以在加载时候，对于已经加载过的item,  采用比对tag方式判断是否需要重新计算高度
*/
            holder.setImageStr(R.id.iv_img, item.goodsthumb);
//            ivImg.setTag(imgPath);
   /*     }*/

        holder.setText(R.id.tv_price, item.goodsprice);
        holder.setText(R.id.tv_desc, item.goodsname);
        holder.getParentView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (EmptyUtils.isEmpty(SPUtils.getShareString(Constans.HASHID))) {
                    Intent intent = new Intent(mContext, LoginActivtiy.class);
                    mContext.startActivity(intent);
                    return;
                }
                Intent intent = new Intent(mContext, JinPaiDetailActivity.class);
                intent.putExtra(JinPaiDetailActivity.INFOBEAN, item);
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    protected int getItemViewLayoutId(int position, HomeEntity.ListsEntity item) {
        return R.layout.item_home;
    }
    @Override
    public long getItemId(int position) {
        return mData.get(position).hashCode();
    }
}
